﻿@inject ISettingService _settingService
@inject IRepository<MotionGroupModel> _motionGroupRepository
@inject IJSRuntime JS
@inject ILive2DService _live2DService

<CnGalWebSite.Kanban.Components.Shared.FloatButton Image="./_content/CnGalWebSite.Kanban/images/motion.png" ShowMenu Tooltip="动作" Class="cngal-kanban-set-motion">
     <MenuContent>
         <MDCard>
             <MList Dense>
                @foreach (var item in _motionGroupRepository.GetAll())
                {
                    <MSubheader>@item.DisplayName</MSubheader>
                    <MListItemGroup Value="null" ValueChanged="@((e)=>ValueChanged(item,e))"
                                    Color="primary">
                        @foreach (var info in item.Motions)
                        {
                            <MListItem>
                                <MListItemContent>
                                    <MListItemTitle>@info.Name</MListItemTitle>
                                </MListItemContent>
                            </MListItem>
                        }
                        @if (_motionGroupRepository.GetAll().IndexOf(item) == _motionGroupRepository.GetAll().Count - 1)
                        {
                            <MListItem>
                                <MListItemContent>
                                    <MListItemTitle>清空</MListItemTitle>
                                </MListItemContent>
                            </MListItem>
                        }

                    </MListItemGroup>
                }

            </MList>
         </MDCard>
    </MenuContent>
</CnGalWebSite.Kanban.Components.Shared.FloatButton>

@code {

    public async Task ValueChanged(MotionGroupModel model, StringNumber index)
    {
        if (index.ToInt32() == model.Motions.Count)
        {
            await _live2DService.CleanMotion();
        }
        else
        {
            await _live2DService.SetMotion(model.Name, index.ToInt32());
        }
    }
}
